home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / JAVA / AWT / Choice.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  1.8 KB  |  81 lines

  1. package java.awt;
  2.  
  3. import java.awt.peer.ChoicePeer;
  4. import java.util.Vector;
  5.  
  6. public class Choice extends Component {
  7.    Vector pItems = new Vector();
  8.    int selectedIndex = -1;
  9.  
  10.    public synchronized void addNotify() {
  11.       super.peer = ((Component)this).getToolkit().createChoice(this);
  12.       super.addNotify();
  13.    }
  14.  
  15.    public int countItems() {
  16.       Vector var1 = this.pItems;
  17.       return var1.elementCount;
  18.    }
  19.  
  20.    public String getItem(int var1) {
  21.       return (String)this.pItems.elementAt(var1);
  22.    }
  23.  
  24.    public synchronized void addItem(String var1) {
  25.       if (var1 == null) {
  26.          throw new NullPointerException();
  27.       } else {
  28.          this.pItems.addElement(var1);
  29.          ChoicePeer var2 = (ChoicePeer)super.peer;
  30.          if (var2 != null) {
  31.             Vector var3 = this.pItems;
  32.             var2.addItem(var1, var3.elementCount - 1);
  33.          }
  34.  
  35.          if (this.selectedIndex < 0) {
  36.             this.select(0);
  37.          }
  38.  
  39.       }
  40.    }
  41.  
  42.    public String getSelectedItem() {
  43.       int var1 = this.selectedIndex;
  44.       return var1 >= 0 ? this.getItem(var1) : null;
  45.    }
  46.  
  47.    public int getSelectedIndex() {
  48.       return this.selectedIndex;
  49.    }
  50.  
  51.    public synchronized void select(int var1) {
  52.       Vector var2 = this.pItems;
  53.       if (var1 >= var2.elementCount) {
  54.          throw new IllegalArgumentException("illegal Choice item position: " + var1);
  55.       } else {
  56.          var2 = this.pItems;
  57.          if (var2.elementCount > 0) {
  58.             this.selectedIndex = var1;
  59.             ChoicePeer var4 = (ChoicePeer)super.peer;
  60.             if (var4 != null) {
  61.                var4.select(var1);
  62.             }
  63.          }
  64.  
  65.       }
  66.    }
  67.  
  68.    public void select(String var1) {
  69.       Vector var2 = this.pItems;
  70.       int var4 = var2.indexOf(var1, 0);
  71.       if (var4 >= 0) {
  72.          this.select(var4);
  73.       }
  74.  
  75.    }
  76.  
  77.    protected String paramString() {
  78.       return super.paramString() + ",current=" + this.getSelectedItem();
  79.    }
  80. }
  81.